const app = new BasicTableVue({
    data() {
        return {
            api: tlogAlarmApi,
            columns: [
                new TableColumn({width: 30, type: 'selection'}),
                new TableColumn({prop: 'id', title: 'ID'}),
                new TableColumn({prop: 'alarmType', title: '类型', formatter: this.alarmTypeFormat}),
                new TableColumn({prop: 'level', title: '级别', formatter: this.levelFormat}),
                new TableColumn({prop: 'alarmTime', title: '告警时间', formatter: TableColumn.datetimeFormat}),
                new TableColumn({prop: 'comments', title: '备注'}),
                new TableColumn({prop: 'viewStatus', title: '处理状态', formatter: this.viewStatusFormat}),
                new TableColumn({prop: 'operating', title: '操作', customComponent: true})
            ],
            //级别， 1：警告，2：危险
            levelMap: new Map().set(1, '警告').set(2, '危险'),
            alarmTypeMap: new Map().set(1, '上报失败').set(2, '调用外部接口失败').set(3, '调用内部接口失败').set(4, '基础数据错误'),
            viewStatusMap: new Map().set(1, '未查看').set(2, '已查看').set(3, '请联系系统管理员'),
        }
    },
    methods: {
        createForm() {
            return new TlogAlarmVo()
        },
        async init() {

        },
        levelFormat: function (row, column, val, key) {
            return this.levelMap.get(parseInt(val));
        },
        alarmTypeFormat: function (row, column, val, key) {
            return this.alarmTypeMap.get(parseInt(val));
        },
        viewStatusFormat: function (row, column, val, key) {
            return this.viewStatusMap.get(parseInt(val));
        },
        retry(data) {

        },
        async forwardUpdate(data) {
            await tlogAlarmApi.updateViewStatusToViewed(data.id)
            switch (data.verifyType) {
                case 1:
                    forward('/basic-data/modify/admin_idc_info_modify', await baseOperCompanyApi.get(data.dealId));
                    break;
                case 2:
                case 3:
                    forward('/basic-data/modify/admin_house_info_modify', await baseHouseInfoApi.get(data.dealId));
                    break;
                case 4:
                    forward('/basic-data/modify/admin_frameinfo_modify', await baseFrameInfoApi.get(data.dealId));
                    break;
                case 5:
                    forward('/basic-data/modify/admin_ip_seg_info_modify', await baseIpAddressInfoApi.get(data.dealId));
                    break;
                case 6:
                    forward('/basic-data/modify/admin_user_info_modify', await baseCustomerApi.get(data.dealId));
                    break;
                case 7:
                    let idByServiceInfo = data.dealId.split(',')
                    forward('/basic-data/modify/admin_user_info_modify', await baseCustomerApi.getByServiceId(idByServiceInfo[0], idByServiceInfo[1]));
                    break;
                case 8:
                    let idByHouseHoldInfo = data.dealId.split(',')
                    forward('/basic-data/modify/admin_user_info_modify', await baseCustomerApi.getByHoldId(idByHouseHoldInfo[0], idByHouseHoldInfo[1]));
                    break;
            }
        },
        async forwardUpdateViewStatus(data) {
            await tlogAlarmApi.updateViewStatusToViewed(data.id)
            data.viewStatus = 2
        }
    },
    beforeMount() {
        if (forward.getData() !== '{}' && JSON.stringify(forward.getData()) !== '{}') {
            this.form = forward.getData()
        }
    }
})
